//Klasse om connectie met de database te maken

package persistentie;

import java.sql.DriverManager;


import javax.swing.JOptionPane;
import java.sql.SQLException;
import java.sql.Connection;
public class Connectie {

	private static final String JDBC_DRIVER = "sun.jdbc.odbc.JdbcOdbcDriver";

	private static final String DATABASE_URL = "jdbc:odbc:MS Access-database;DBQ=binfsea";

	private Connection connection;

	/**
	 * @directed true
	 */

	public Connectie() {
		try {
			Class.forName(JDBC_DRIVER);
			connection = DriverManager.getConnection(DATABASE_URL);
		} catch (SQLException sqlException) {
			JOptionPane.showMessageDialog(null, sqlException.getMessage(),"database probleem", JOptionPane.ERROR_MESSAGE);
			System.exit(1);
		}
		catch (ClassNotFoundException classNotFound) {
			JOptionPane.showMessageDialog(null, classNotFound.getMessage(),"Driver Not Found", JOptionPane.ERROR_MESSAGE);
			System.exit(1);
		}
	}

	public void closeConnection() {
		try {
			connection.close();
		}
		catch (SQLException sqlException) {
			JOptionPane.showMessageDialog(null, sqlException.getMessage(),"Database Error", JOptionPane.ERROR_MESSAGE);

			System.exit(1);
		}
	}

	public Connection getConnection() {
		return connection;
	}
}